//
//  KABMineUserListTCell.m
//  kabu
//
//  Created by XiangDongMBP on 2017/2/16.
//  Copyright © 2017年 East. All rights reserved.
//

#import "KABMineUserListTCell.h"
#import "GlobalHeader.h"
#import "UIColor+XDHex.h"
#import "KABModel.h"
#import <YYWebImage.h>

@implementation KABMineUserListTCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.followBtn.layer.borderWidth = 1;
    self.followBtn.layer.cornerRadius = CGRectGetHeight(self.followBtn.bounds) / 2.0;
    self.followBtn.layer.borderColor = [UIColor xd_colorWithHex:KABGlobalColorTabBarItemColor].CGColor;
    [self.followBtn addTarget:self action:@selector(followBtnTapped:) forControlEvents:UIControlEventTouchUpInside];
    
    self.portraitImgView.layer.masksToBounds = YES;
    self.portraitImgView.layer.cornerRadius = CGRectGetWidth(self.portraitImgView.bounds) / 2.0;
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(portraitImgViewTapped:)];
    [self.portraitImgView addGestureRecognizer:tapGesture];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)portraitImgViewTapped:(UIGestureRecognizer *)gesture {
    if ([self.delegate respondsToSelector:@selector(kABMineUserListTCell:portraitTapped:)]) {
        [self.delegate kABMineUserListTCell:self portraitTapped:(UIImageView *)gesture.view];
    }
}

- (void)followBtnTapped:(UIButton *)btn {
    if ([self.delegate respondsToSelector:@selector(kABMineUserListTCell:followBtnTapped:)]) {
        [self.delegate kABMineUserListTCell:self followBtnTapped:btn];
    }
}

- (void)configViewWithUserItem:(KABMineUserItem *)item {
    [self.portraitImgView yy_setImageWithURL:[NSURL URLWithString:item.headimg_url]
                                 placeholder:[KABDefaultVarModel sharedInstance].smallDefaultImg];
    self.nameLabel.text = item.nick_name;
    self.autographLabel.text = item.sign;
    self.followBtn.selected = (item.follow_state & 0x01);
    if (item.follow_state & 0x01) {
        NSString * title = @"已关注";
        if (item.follow_state & 0x02) {
            title = @"互粉";
        }
        [self.followBtn setTitle:title forState:UIControlStateSelected];
    }
    self.followBtn.backgroundColor = self.followBtn.selected ? [UIColor whiteColor] : [UIColor xd_colorWithHex:KABGlobalColorTabBarItemColor];
}

@end
